from datetime import datetime

from sqlalchemy import Column, DateTime, Float, Integer, String, Text

from app.db.base_class import Base


class PUAPatternCategory:
    GASLIGHTING = "gaslighting"  # 煤气灯效应
    LOVE_BOMBING = "love_bombing"  # 爱情轰炸
    NEGGING = "negging"  # 负面评价
    ISOLATION = "isolation"  # 隔离控制
    TRIANGULATION = "triangulation"  # 三角关系
    SILENT_TREATMENT = "silent_treatment"  # 冷暴力
    GUILT_TRIPPING = "guilt_tripping"  # 罪恶感操纵
    BREADCRUMBING = "breadcrumbing"  # 面包屑喂养
    OTHER = "other"


class PUAPattern(Base):
    """PUA模式识别表"""
    id = Column(Integer, primary_key=True, index=True)
    pattern = Column(String(200), nullable=False, comment="PUA模式表达式")
    category = Column(
        String(50), 
        default=PUAPatternCategory.OTHER, 
        comment="模式类别"
    )
    description = Column(Text, nullable=True, comment="模式描述")
    severity = Column(Float, default=0.5, comment="严重程度(0-1之间)")
    examples = Column(Text, nullable=True, comment="示例(JSON数组)")
    response_templates = Column(Text, nullable=True, comment="建议回复模板(JSON数组)")
    created_at = Column(DateTime, default=datetime.utcnow, comment="创建时间")
    updated_at = Column(
        DateTime, 
        default=datetime.utcnow,
        onupdate=datetime.utcnow,
        comment="更新时间"
    )
    
    def __repr__(self):
        return f"<PUAPattern {self.category}: {self.pattern[:30]}>"